<template>
    <div style="margin-top:2rem;margin-bottom:2rem;">
    <el-row>
      <el-col :span="3" :offset="21">
        <el-button type="primary" @click="newPositionMatching">新增</el-button>
      </el-col>
    </el-row>
    <el-row style="margin-top:2rem;">
      <el-col>
        <el-table :data="tableData" style="width: 100%">
          <el-table-column label="职位" prop="jobPosition">
          </el-table-column>
          <el-table-column label="表达式" prop="expression">
          </el-table-column>
          <el-table-column label="优先级" width="120" prop="sortNum">
          </el-table-column>
          <el-table-column label="操作" width="220">
            <template slot-scope="scope">
              <el-button size="mini" @click="editPositionMatching(scope.row)">编辑</el-button>
              <el-button size="mini" type="danger" @click=" deleteOne(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
    <New ref="new" @fnc="getData"/>
    <Edit ref="edit" @fnc="getData"></Edit>
    </div>
</template>
<script>
import New from './position-new'
import Edit from './position-edit'
import _ from 'lodash'
export default{
    components:{
        New,
        Edit
    },
    data:function(){
        return {
            tableData:[]
        }
    },
    created(){
        this.getData()
    },
    methods:{
        getData() {
        this.$http({
          url: `${this.$http.adornUrl('/jobPositionMatching/list?token='+this.$cookie.get('token') )}`,
          method: 'get',
        }).then(data => {
          this.tableData = data.data.data
        })
      },
      newPositionMatching(){
          this.$refs.new.init()
      },
      editPositionMatching(row){
          let data = _.cloneDeep(row)
          this.$refs.edit.init(data)
      },
      //删除
      deleteOne(row) {
        this.rowData = row
        this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: `${this.$http.adornUrl('/jobPositionMatching/'+row.id+'?token='+this.$cookie.get('token') )}`,
            method: 'delete',
          }).then(({
            data
          }) => {
            if (data['code'] == 0) {
              this.$message({
                message: '删除成功',
                type: 'success'
              });
              this.getData()
            } else {
              this.$message({
                message: '数据删除错误',
                type: 'error'
              });
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
    }
}
</script>